from configparser import ConfigParser
"""
ConfigParser 读取配置文件和写入配置文件
"""
# 读取ini文件方法
config = ConfigParser()  # 实例化对象
config.read("config.ini")  # 读取哪一个文件
# value = config.get("URL","uat_base_url")  # 查看某一个选项
# print(value)

# 修改ini文件:option 选项
# config.set('URL','dev_base_url',"DEV_BASE_URL")
"""
dev_base_url：找到你要修改的option
DEV_BASE_URL：将option改为这个
"""
# with open('config.ini','w',encoding='utf-8') as f:
#     config.write(f)  # 重新覆盖写入
# 查看是否修改成功
# value = config.get("URL",'dev_base_url')  # 再次查看
# print(value) # 值被改掉
# config.set('DATABASE','dev_database_ip','222.22.3.3')
# with open('config.ini','w',encoding='utf-8') as f:
#     config.write(f)
# # 查看是否修改成功
# value = config.get("DATABASE","dev_database_ip")
# print(value)

# 删除一个选项（option）
# config.remove_option('URL','dev_base_url')
# with open('config.ini','w',encoding='utf-8') as f:
#     config.write(f)

# 删除一个节（section）
"""
config.remove_section("DATABASE")
with open('config.ini','w',encoding='utf-8') as f:
    config.write(f)
"""

# 查看某个选项是否存在于节
# r = config.has_option('URL','sit_base_url')
# print(r)














